﻿<include file="Public:header" />
<script charset="utf-8" src="/editor/kindeditor.js"></script>
<script charset="utf-8" src="/editor/lang/zh_CN.js"></script>
<script>
	var editor;
	KindEditor.ready(function(K) {
			editor = K.create('#description',{
					langType : 'en'
				});
	});
		
	function form_check(){
		if($("#product_name_id").val()==""){
			alert("Title can not empty!");
			return false;
		}
		return true;
	}
	
	$(document).ready(function(){
		$(function() {
			$( "#time_expire" ).datepicker({ dateFormat: 'yy-mm-dd' });
		});
	});
	//time_expire
	
	function del_img(img_name,filename){
		if(confirm("Remove?")){
			//location="{$SITE_URL}/admin.php?s=/Product/del_img/pid/{$Think.get.pid}/img_name/<?php echo urlencode($vo['imagename']); ?>";
			$.ajax({ 
					type: "post", 
					url: "{$SITE_URL}/admin.php?s=/Product/del_img/pid/{$Think.get.pid}/img_name/"+img_name, 
					dataType: "json", 
					success: function (data) { 
							rv = data.data;
							if(rv.status == 1){
								
								$("#img_li_"+filename).hide();
							}else{
							}
							//alert(data.data); 
					}, 
					error: function (XMLHttpRequest, textStatus, errorThrown) { 
							//alert(errorThrown); 
					} 
			});
		}
	}
	
	$(document).ready(function(e) {
        //$("#img_li_"+"4f0fb590233d5").hide();
    });
</script>
<div id="content">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td>
      <div style='float:right;padding-right:8px;'>
        <!--  //保留接口  -->
      </div></td>
  </tr>
  <tr>
    <td height="1" style='padding:0px'></td>
  </tr>
</table>
<form id="add_cat" name="add_cat" method="post" action="#" enctype="multipart/form-data"  onsubmit="return form_check();" >
<table width="98%" align="center" border="0" cellpadding="3" cellspacing="1" bgcolor="#CBD8AC" style="margin-bottom:8px;margin-top:8px;">
  <tr>
    <td colspan="2" bgcolor="#EEF4EA" class='title'><span>Update Product</span></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="150"><div align="right">Product Name&nbsp; </div></td>
    <td width=""><input name="name" id="product_name_id" type="text" size="30" value="{$data.tb_products.name}" />&nbsp; <font color="#FF0000">*</font></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="150"><div align="right">User ID&nbsp; </div></td>
    <td width="">
		<input name="user_id" value="" />
    </td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="150"><div align="right">Type&nbsp; </div></td>
    <td width="">
	<select name="type" id="type">
	   <option value="1" <eq name="data.tb_products.type" value="1" >selected="selected"</eq> >Supply</option>
       <option value="2" <eq name="data.tb_products.type" value="2" >selected="selected"</eq> >Demand</option>
	</select>	</td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="150"><div align="right">Category&nbsp; </div></td>
    <td width="">
     <?php
      //var_dump($data["tb_products"]["cat_id"]);
     ?>
     <select name="cat_id" id="cat_id">
     <?php
      foreach($categoty as $key => $value){
     ?>
     	<option value="<?php echo $key; ?>" <?php if($key == $data["tb_products"]["cat_id"]){ ?>selected="selected" <?php } ?> > <?php echo $value; ?></option>
     <?php
    //var_dump($data["tb_products"]["cat_id"]);
    //var_dump($key); exit;
    }
    ?>
      </select>
    
    </td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="18%"><div align="right">Region&nbsp; </div></td>
    <td width="82%">
	<select name="location_code" id="location_code_id">
	  <foreach name="all_regions" item="vo">
	   <option value="{$vo.region_code}" <?php  if($vo["region_code"] == $data["tb_products"]["location_code"]){ ?>selected="selected" <?php } ?>>{$vo.region_country}/{$vo.region_province}</option>
	  </foreach>
	</select>	</td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="150"><div align="right">Image&nbsp; </div></td>
    <td width="">

<style>
.product_photo { padding:0; margin:0; }
.product_photo li { list-style:none; margin-right:10px; border-bottom:#eee solid 1px; padding:10px; overflow:hidden; }
.product_photo li img  {  width:50px; height:50px; float:left; margin-right:10px; padding:2px; border:#ccc solid 1px;  }
.product_photo li input {  }
</style>    
    
    
    <?php 
        $images = explode(",",$data["tb_products"]["image"]);
        
        //image name without extension
        foreach($images as $key => $value){
       		$filenames[$key]["imagename"] = $value;
        	$filetype = strrchr($value, ".");
        	$value = str_replace($filetype,"",$value);
        	$filenames[$key]["filename"] = $value;
            $filenames[$key]["filetype"] = $filetype;
        }
        /////var_dump($filenames);
    ?>
            
        <ul class="product_photo">
        	<foreach name="filenames" item="vo">
                <li id="img_li_{$vo['filename']}">       
                <notempty name="vo">      
                    <img src="{$SITE_URL}/public/uploads/images/{$vo.imagename}"  />
                    <a href="javascript:del_img('<?php echo urlencode($vo['imagename']); ?>', '{$vo['filename']}' );">Remove Image</a>
                </notempty>
                <empty name="vo">      
                    <img src="{$SITE_URL}/public/uploads/images/no-image.jpg" />
                </empty>
                </li>
            </foreach>
        </ul>
        
        <input name="image[]" type="file" size="30" /><br />
        <input name="image[]" type="file" size="30" /><br />
        <input name="image[]" type="file" size="30" /><br />
        <input name="image[]" type="file" size="30" /><br />
        <input name="image[]" type="file" size="30" /><br />
        <input name="image[]" type="file" size="30" /><br />
        <!--
    	<label>Max Width:</label><input type="text" name="thumbMaxWidth" id="thumbMaxWidth" size="10" value="" />&nbsp;
        <label>Max Height:</label><input type="text" name="thumbMaxHeight" id="thumbMaxHeight" size="10" value="" /><br />
        -->
    </td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="150"><div align="right">Price&nbsp; </div></td>
    <td width=""><input name="price" type="text" size="15" value="{$data.tb_products.price}" />&nbsp;</td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="150"><div align="right">Quantity&nbsp; </div></td>
    <td width=""><input name="quantity" type="text" size="15" value="{$data.tb_products.quantity}" />&nbsp;</td>
  </tr>
  <tr bgcolor="#FFFFFF">
        <td width="150"><div align="right">Description &nbsp; </div></td>
        <td width=""><textarea name="description" id="description" style="width:700px;height:200px;visibility:hidden;">{$data.tb_products.description}</textarea></td>
    </tr>
    <tr bgcolor="#FFFFFF">
        <td width="150"><div align="right">Expire at: &nbsp; </div></td>
        <td width=""><input name="time_expire" id="time_expire" type="text" size="15" value="<?php echo date('Y-m-d', $data['tb_products']['time_expire'] ); ?>" /></td>
    </tr>
   
  <tr bgcolor="#FFFFFF">
    <td colspan="2">
	<div align="center">
    		<input type="submit" name="Submit" value="Update"> 
			<input type="reset" name="chongzhi" value="Reset">
	</div>
	</td>
  </tr>
</table>
</form>
</div>
<include file="Public:footer" />